//
//  BaseNavigationViewController.swift
//  sss
//
//  Created by MAC on 2020/12/24.
//  Copyright © 2020 hrrMac. All rights reserved.
//

import UIKit

class BaseNavigationViewController: UINavigationController, UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        if(self .responds(to: #selector(getter: interactivePopGestureRecognizer))){
            self.interactivePopGestureRecognizer?.delegate = self
        }

    }
    
    ///配置导航栏
    func configCustomNavigationBar(_ bgImgStr :String , color : UIColor = UIColor.black , font : UIFont = UIFont.systemFont(ofSize: 18)){
        navigationBar.backgroundColor = UIColor.white
        navigationBar.isTranslucent = false
        
        var textAttributes : [NSAttributedString.Key:AnyObject] = [:]
        textAttributes[.foregroundColor] = color
        textAttributes[.font] = font
        navigationBar.titleTextAttributes = textAttributes
        
        navigationBar.setBackgroundImage( UIImage(named: bgImgStr), for: .any, barMetrics: .default)
        
    }
    
    
    ///配置侧滑返回功能 需要隐藏导航栏的界面 viewController.view 的tag 设置为10086
    func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
        if visibleViewController?.view.tag == 10086 {
            return false
        }
        if gestureRecognizer == self.interactivePopGestureRecognizer {
            if viewControllers.count < 2 || self.visibleViewController == viewControllers.first {
                return false
            }
        }
        return true
    }

}
